$os: "" !default;
$theme: "" !default;

/* 目录 */
.md-toc {
  font-size: var(--toc-font-size);
}
.md-toc-content {
  margin-left: 2em;
  /* 修复缺失上级标题时无法递增 */
  counter-reset: toc-h2 toc-h3 toc-h4 toc-h5 toc-h6;
  break-after: page;
}
.md-toc-inner {
  margin-left: 0 !important;
  @if $theme == "light" {
    color: var(--text-color) !important;
  } @else if $theme == "dark" {
    color: #dddddd !important;
  }
}
.md-toc-item {
  @if $theme == "light" {
    color: var(--text-color) !important;
  } @else if $theme == "dark" {
    color: #dddddd !important;
  }
}

/* 目录标题内容属性 */
.md-toc-h2,
.md-toc-h3,
.md-toc-h4,
.md-toc-h5,
.md-toc-h6 {
  font-size: var(--toc-font-size);
  font-family: var(--toc-font), var(--base-latin-font), var(--base-chinese-font),
    serif;
}
.md-toc-h2 {
  font-weight: var(--strong-weight);
}

/* 目录标题前 */
.md-toc-content {
  .md-toc-h1 {
    display: var(--toc-show-title);
    counter-reset: toc-h2 toc-h3 toc-h4 toc-h5 toc-h6;
  }
  .md-toc-h2 {
    // 确保 h2 重置 h3 及其后续计数器
    counter-reset: toc-h3 toc-h4 toc-h5 toc-h6;
  }
  .md-toc-h3 {
    counter-reset: toc-h4 toc-h5 toc-h6;
  }
  .md-toc-h4 {
    counter-reset: toc-h5 toc-h6;
  }
  .md-toc-h5 {
    counter-reset: toc-h6;
  }

  @supports (counter-set: none) {
    .md-toc-h1 {
      counter-set: toc-h2 0 toc-h3 0 toc-h4 0 toc-h5 0 toc-h6 0;
      counter-reset: none;
    }
    .md-toc-h2 {
      counter-set: toc-h3 0 toc-h4 0 toc-h5 0 toc-h6 0;
      counter-reset: none;
    }
    .md-toc-h3 {
      counter-set: toc-h4 0 toc-h5 0 toc-h6 0;
      counter-reset: none;
    }
    .md-toc-h4 {
      counter-set: toc-h5 0 toc-h6 0;
      counter-reset: none;
    }
    .md-toc-h5 {
      counter-set: toc-h6 0;
      counter-reset: none-h6;
    }
  }

  .md-toc-h2:before {
    counter-increment: toc-h2;
    content: counter(toc-h2);
    margin-right: 1em;
    font-weight: var(--strong-weight);
  }
  .md-toc-h3:before {
    counter-increment: toc-h3;
    content: counter(toc-h2) "." counter(toc-h3);
    margin-left: 1.5em;
    margin-right: 0.5em;
  }
  .md-toc-h4:before {
    counter-increment: toc-h4;
    content: counter(toc-h2) "." counter(toc-h3) "." counter(toc-h4);
    margin-left: 3.5em;
    margin-right: 0.5em;
  }
  .md-toc-h5:before {
    counter-increment: toc-h5;
    content: counter(toc-h2) "." counter(toc-h3) "." counter(toc-h4) "."
      counter(toc-h5);
    margin-left: 5.5em;
    margin-right: 0.5em;
  }
  .md-toc-h6:before {
    counter-increment: toc-h6;
    content: counter(toc-h2) "." counter(toc-h3) "." counter(toc-h4) "."
      counter(toc-h5) "." counter(toc-h6);
    margin-left: 7.5em;
    margin-right: 0.5em;
  }
}